package com.example.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import java.io.IOException;

public class MyWebSocketService extends Service {
    private MyWebSocketServer webSocketServer;

    @Override
    public void onCreate() {
        super.onCreate();
        new Thread(new Runnable() {
            @Override
            public void run() {
                // 创建并启动 WebSocket 服务器
                webSocketServer = new MyWebSocketServer(8080); // 指定服务器端口
                webSocketServer.start();
            }
        }).start();

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.e("msg","服务关闭");
        //如果没有设置前台服务,应用退到后台,过十几秒service就会死掉
        //这边不建议关联关闭websocketService.不然就会死掉
    }

    @Override
    public IBinder onBind(Intent intent) {
        // 如果该服务不提供绑定，则返回 null
        return null;
    }
}